function [sudoku_sol, cube_sol, marche, fini] = resol_facile(sudoku_depart)

% Fonction permettant de resoudre les cases evidentes d'un sudoku, celles ou il n'y a qu'une seule possibilite.

sudoku_temp = sudoku_depart;

marche = 1;
fini = 0;

cube = ones(9, 9, 9);

modif = true;

for i = 1:9
	for j = 1:9
		if sudoku_temp(i, j) ~=0
			k = sudoku_temp(i, j);
			cube = maj(cube, i, j, k);
		end
	end
end


while (modif)
	modif = false;
	i = 1;
	cont = true;
	while (i ~= 10 && cont)
		j = 1;
		while(j ~= 10 && cont)
			S = sum(cube(i, j, :));
			if (S == 1)
				fin = false;
				k = 1;
				while ~fin
					if (cube(i, j, k) == 1)
						fin = true;
						sudoku_temp(i, j) = k;
						cube = maj(cube, i, j, k);
						cont = false;
						modif = true;
					end
					k = k + 1;
				end
			end
			j = j + 1;
		end
		i = i + 1;
	end

	if (~modif)
		i = 1;
		cont = true;
		while(i ~= 10 && cont)
			k = 1;
			while(k ~= 10 && cont)
				S = sum(cube(i, :, k));
				if (S == 1)
					fin = false;
					j = 1;
					while ~fin
						if (cube(i, j, k) == 1)
							fin = true;
							sudoku_temp(i, j) = k;
							cube = maj(cube, i, j, k);
							cont = false;
							modif = true;
						end
						j = j + 1;
					end
				end
				k = k + 1;
			end
			i = i + 1;
		end

		if ~modif
			j = 1;
			cont = true;
			while(j ~= 10 && cont)
				k = 1;
				while(k ~= 10 && cont)
					S = sum(cube(:, j, k));
					if (S == 1)
						fin = false;
						i = 1;
						while ~fin
							if (cube(i, j, k) == 1)
								fin = true;
								sudoku_temp(i, j) = k;
								cube = maj(cube, i, j, k);
								cont = false;
								modif = true;
							end
							i = i + 1;
						end
					end
					k = k + 1;
				end
				j = j + 1;
			end

			if ~modif
				icarre = 1;
				cont = true;
				while (icarre ~= 4 && cont)
					jcarre = 1;
					while (jcarre ~= 4 && cont)
						k = 1;
						debut_carre_i = icarre*3 - 2;
						fin_carre_i = icarre*3;
						debut_carre_j = jcarre*3 -2;
						fin_carre_j = jcarre*3;

						S = sum(sum(cube(debut_carre_i:fin_carre_i,debut_carre_j:fin_carre_j,k), 1));
						if (S == 1)
							fin = false;
							i = debut_carre_i;
							while(i < fin_carre_i + 1 && ~fin)
								j = debut_carre_j;
								while(j < fin_carre_j + 1 && ~fin)
									if (cube(i, j, k) == 1)
										fin = true;
										sudoku_temp(i, j) = k;
										cube = maj(cube, i, j, k);
										cont = false;
										modif = true;
									end
									j = j + 1;
								end
								i = i + 1;
							end
						end
						jcarre = jcarre + 1;
					end
					icarre = icarre + 1;
				end
			end
		end
	end
end



if (cube == 0)
	for i = 1:9
		for j = 1:9
			if (sudoku_temp(i, j) == 0)
				marche = 0;
				break;
			end
		end
	end
	if (marche == 1)
		fini = 1;
	end
else
	if (marche == 1)
		fini = 0;
	end
end


sudoku_sol = sudoku_temp;
cube_sol = cube;
marche;
fini;
return;
